#ifndef X_9_H
#define X_9_H

#include "common.h"

template <AllegroVersion version>
struct x09
{
    uint32_t t;
    uint32_t k;
    
    // Always null?
    uint32_t un1[4];
    
    // Points to `x28`, `x32`, or `x33` (sometimes null)
    uint32_t ptr1;
    
    // Points to `x05` or `x09`
    uint32_t ptr2;
    
    // Always null?
    uint32_t un2;
    
    // Points to `x28`, `x32`, or `x33
    uint32_t ptr3;
    
    uint32_t ptr4;
    
    uint32_t TAIL;
    operator x09<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_172, A_174};
};

#if __cplusplus >= 202002L
template <AllegroVersion version> requires(version >= A_172)
struct x09<version>
{
    uint32_t t;
    uint32_t k;

    // Always null?
    uint32_t un1[4];
    uint32_t un3;

    // Points to `x28`, `x32`, or `x33` (sometimes null)
    uint32_t ptr1;

    // Points to `x05` or `x09`
    uint32_t ptr2;

    // Always null?
    uint32_t un2;

    // Points to `x28`, `x32`, or `x33
    uint32_t ptr3;

    uint32_t ptr4;

    COND_FIELD(version >= A_174, uint32_t, un4);

    uint32_t TAIL;
    operator x09<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_172, A_174};
};
#else
template <> struct x09<A_172>
{
    uint32_t t;
    uint32_t k;

    // Always null?
    uint32_t un1[4];
    uint32_t un3;

    // Points to `x28`, `x32`, or `x33` (sometimes null)
    uint32_t ptr1;

    // Points to `x05` or `x09`
    uint32_t ptr2;

    // Always null?
    uint32_t un2;

    // Points to `x28`, `x32`, or `x33
    uint32_t ptr3;

    uint32_t ptr4;

    uint32_t TAIL;
    operator x09<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_172, A_174};
};

template <> struct x09<A_174>
{
    uint32_t t;
    uint32_t k;

    // Always null?
    uint32_t un1[4];
    uint32_t un3;

    // Points to `x28`, `x32`, or `x33` (sometimes null)
    uint32_t ptr1;

    // Points to `x05` or `x09`
    uint32_t ptr2;

    // Always null?
    uint32_t un2;

    // Points to `x28`, `x32`, or `x33
    uint32_t ptr3;

    uint32_t ptr4;

    uint32_t un4;

    uint32_t TAIL;
    operator x09<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_172, A_174};
};
#endif

#endif // X_9_H
